// pages/verification/verification.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    second: 60,
    isResend: false,
    checkCode:'',
    cashApplyNumber:'',
    type:'',
    orgid:'',
    adminTel:'',
    adminTel1: '',
  },
  onCodeChange(e){
    this.toggle("checkCode", e.detail.value)
  },
  sendCode() {
    var that = this
    if (!that.data.isResend) {
      var url = "orgmini/sys/sendCode?telphone=" +that.data.adminTel + "&type=13"
      app.req({
        url: url,
        success: function (res) {
          if (200 == res.code) {
            that.toggle("isResend", true)
            var timer = setInterval(function () {
              that.toggle("second", --that.data.second)
              if (that.data.second < 0) {
                clearInterval(timer)
                that.toggle("isResend", false)
                that.toggle("second", 60)
              }
            }, 1000)
          }
        }
      });
    }
  },
  toggle(type, val) {
    this.setData({
      [type]: val
    });
  },
  save(){
    var that = this
    if (that.data.checkCode.length<6){
      wx.showToast({
        title: '验证码格式有误',
      })
      return
    }
    console.log('传值', that.data.orgid + '&type=' + that.data.type + '&cashApplyNumber=' + that.data.cashApplyNumber)
    app.req({
      url: "orgmini/orgAccount/checkAdminCode",
      data: {
        adminTel: that.data.adminTel,
        code: that.data.checkCode
      },
      success: function (res) {
        if (200 == res.code) {
          wx.navigateTo({
            url: '/pages/orgAuditor/orgAuditor?id=' + that.data.orgid + '&type=' + that.data.type + '&cashApplyNumber=' + that.data.cashApplyNumber
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      orgid: options.id,
      type:options.type,
      cashApplyNumber: options.cashApplyNumber,
      adminTel: options.adminTel,
      adminTel1: options.adminTel.substring(0, 3) + '****' + options.adminTel.substring(7)
    })  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})